package com.itheima.Controller;


import com.itheima.Pojo.LoginInfo;
import com.itheima.Pojo.Result;
import com.itheima.Pojo.Student;
import com.itheima.Pojo.Teacher;
import com.itheima.Service.LoginServise;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录Controller
 */
@Slf4j
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private LoginServise loginServise;

    /**
     * 登录
     */
    @PostMapping("/login/teacher")
    public Result tea_login(@RequestBody Teacher teacher){
        log.info("登录: {}", teacher);
        LoginInfo info =  loginServise.tea_login(teacher);
        if (info != null){
            return Result.success(info);
        }
        return Result.error("用户名或密码错误");
    }

    @PostMapping("/login/student")
    public Result stu_login(@RequestBody Student student){
        log.info("登录: {}", student);
        LoginInfo info =  loginServise.stu_login(student);
        if (info != null){
            return Result.success(info);
        }
        return Result.error("用户名或密码错误");
    }

}
